{include file="common/header" /}
<link rel="stylesheet" href="__LAYUIMINI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<style>
  body {
    background-color: #ffffff;
  }
  .layui-form-label {
      width: 150px;
  }
  .layui-input-block{
      margin-left: 150px;
  }
</style>

<body>
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>模型添加</legend>
  </fieldset>
  <div class="layui-form layuimini-form">
    
    {volist name="$eg_res" id="vo"}
    <div class="layui-form-item">
      <label class="layui-form-label">{$vo.title}</label>
      <div class="layui-input-block" >
        <input type="radio" name="example_group_id" value="{$vo.id}" title="" lay-filter="checkOne" >
        <div class="xiaji{$vo.id}" >
          {volist name="$vo.e_res" id="vo2" key="key2"}
          <input type="checkbox" name="example_ids[{$vo.id}][{$key2}]" lay-skin="primary" value="{$vo2.id}" title="{$vo2.title}({$vo2.name})">
          {/volist}
        </div>
      </div>
    </div>
    {/volist}
   
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="saveBtn">立即提交</button>
        <a href="{:url('index')}" class="layui-btn layui-btn-primary">返回</a>
      </div>
    </div>
  </div>

  <script>
    layui.use(['form', 'iconPickerFa', 'upload', 'laydate'], function () {
      var form = layui.form,
        iconPickerFa = layui.iconPickerFa,
        layer = layui.layer,
        upload = layui.upload,
        laydate = layui.laydate,
        $ = layui.$;

        form.on('switch(sw)', function(data){
            var obj=data.elem;
            if(data.elem.checked){
                var value=$(obj).attr('data-check');
            }else{
                var value=$(obj).attr('data-nocheck');
            }
            var name=$(obj).attr("data-name");
            $("input[name='"+name+"']").val(value);
        });


      form.on('radio(checkOne)', function(data){
          let val = data.value;
          //$(".layui-input-block input").prop('checked',false);

          if(data.elem.checked){
              $('.xiaji'+val+' input').prop('checked',true);
          }else{
              $('.xiaji'+val+' input').prop('checked',false);
          }
          form.render('checkbox');
      });

      //监听提交
      form.on('submit(saveBtn)', function (data) {
        var index = layer.load(1, {
          shade: [0.3, '#000'] //0.1透明度的白色背景
        });
        var data = data.field;
        // console.log(data)
        // return false
        $.ajax({
          url: "{:url('module/add_group')}",
          data: data,
          type: 'post',
          dataType: 'json',
          success: function (res) {
            // layer.close(index);
            // console.log(res)
            // return false
            if (res.errcode != 1) {
              layer.msg(res.message, { icon: 2, time: 2000 }, function () {
                layer.close(index);
              })
            } else {
              layer.msg(res.message, { icon: 1, time: 1000 }, function () {
                window.location.href = "{:url(CONTROLLER_NAME.'/index')}";
              })
            }
            layer.close(index);
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('网络失败，请刷新页面后重试!', { icon: 2, time: 2000 })
          }
        });

        return false;
      });

    });
  </script>
</body>

</html>